package com.zyw.zhuangdian.config;
import com.zyw.zhuangdian.interceptor.CORSInterceptor;
import com.zyw.zhuangdian.interceptor.JWTInterceptor;
import com.zyw.zhuangdian.property.MyProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private MyProperties properties;

    @Autowired
    private JWTInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        System.out.println(properties);

        registry.addInterceptor(jwtInterceptor).
                addPathPatterns("/**").
                excludePathPatterns("/error").
                excludePathPatterns("/user/login").
                excludePathPatterns("/user/register").
                excludePathPatterns("/user/getVerifyCode").
                excludePathPatterns("/user/forget").
                excludePathPatterns("/user/flush").
                excludePathPatterns("/uploads/**");

        registry.addInterceptor(new CORSInterceptor()).addPathPatterns("/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //增加静态资源访问

        registry.addResourceHandler("/uploads/**").addResourceLocations("file:"+properties.getUpload_file_location());
    }

}
